package com.hulk.dryad.manage.listener;

import com.hulk.dryad.manage.framework.mail.template.MultiMailSendTemplate;
import com.hulk.dryad.manage.listener.event.MailAndJpushEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;


/**
 * mail 消息发送
 *
 * @author hulk
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class MailEventListener {

	private final ObjectProvider<MultiMailSendTemplate> multiMailSendTemplate;

	@EventListener(MailAndJpushEvent.class)
	public void onEvent(MailAndJpushEvent event) {
		String workId = event.getWorkId();
		log.info("邮件发送,workId:[{}] MailAndJPushEvent:[{}]", workId, event);
		String[] receivers = new String[]{event.getReceiver()};
		MultiMailSendTemplate template =	multiMailSendTemplate.getIfAvailable();
		template.customerSend(event.getTitle(), event.getMessage(), receivers);
		log.info("workId:[{}] 邮件发送完成", workId);


	}
}
